package propertiesSelection;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import welcome.general.AboutTool;
import welcome.general.ChoosePerspective;
import DTO.Aspect;
import DTO.ModelGenerated;
import facade.Facade;
import general.AspectLibraryException;

public class PropertySelectionScreen {

	private static final String perspective = "Selection Property Perspective";

	private static JFrame frmSelectionProperty;
	private static PropertySelectionScreen window = null;

	private AboutTool aboutUs = null;

	private Facade facade = Facade.getInstance();

	/* Final components screen. */
	private final JButton btnGenerate = new JButton("generate");
	private final JMenuItem mntmUsingControls = new JMenuItem("Help to use");
	private String[] propertiesNames = {""};
	private final JTextField txtExport = new JTextField();;
	private final JTextField txtImport = new JTextField();;
	private final JTextField txtModelName = new JTextField();;
	
	private JTable table;

	/* Tree components */
	private JScrollPane treeScroll;
	private JTree tree;

	public static JFrame getFrame() {
		return frmSelectionProperty;
	}

	public static PropertySelectionScreen getWindow() {
		return window;
	}

	public PropertySelectionScreen() {
		aboutUs = new AboutTool();
		aboutUs.setVisible(false);

		initialize();
	}

	private void closeFrame(){
		frmSelectionProperty.setVisible(false);
	}

	private void back(){
		closeFrame();
		ChoosePerspective.getChooseAppScreen().setVisible(true);
	}

	private void selectAllOrNoneRows(boolean value){
		for(int rowCount =0; rowCount < table.getModel().getRowCount(); rowCount++){
			if(!table.getModel().getValueAt(rowCount, 0).toString().equals(""))
				table.getModel().setValueAt(value, rowCount, 2);
		}
	}

	public void populateTable(){
		try{
			ArrayList<Aspect> aspects = facade.getPropertiesAndAspects();

			int row =0;
			for(Aspect aspect: aspects){
				table.getModel().setValueAt(aspect.getPropertyAssociatedName(), row, 0);
				table.getModel().setValueAt(aspect.getAspectName(), row, 1);
				table.getModel().setValueAt(false, row, 2);
				row++;
			}
		}catch (SQLException e) {
			// TODO: handle exception
		}
	}

	private void populateTree(){
		final HashMap<String, ArrayList<Aspect>> aspectsNameByProperty = new HashMap<String, ArrayList<Aspect>>();

		for(int rowCount =0; rowCount < table.getModel().getRowCount(); rowCount++){
			if(table.getModel().getValueAt(rowCount,2).toString().equals("true")){
				String propName = table.getModel().getValueAt(rowCount,0).toString();
				String aspectName = table.getModel().getValueAt(rowCount,1).toString();

				if(aspectsNameByProperty.containsKey(propName)){
					aspectsNameByProperty.get(propName).add(new Aspect(aspectName,propName));
				}else{
					ArrayList<Aspect> aspect = new ArrayList<Aspect>();
					aspect.add( new Aspect(aspectName,propName) );

					aspectsNameByProperty.put(propName, aspect);
				}
			}
		}

		// Elements setting.
		if(!aspectsNameByProperty.isEmpty()){
			tree.setModel(new DefaultTreeModel(
					new DefaultMutableTreeNode("TO EXPORT") {
						{
							DefaultMutableTreeNode propNode = null;
							
							List namesProp = new ArrayList(aspectsNameByProperty.keySet());  
							Collections.reverse(namesProp);  
							Iterator namesPropIterator = namesProp.iterator();  
							
							while(namesPropIterator.hasNext()) {  
								Object nameProp = namesPropIterator.next();
								propNode = new DefaultMutableTreeNode(nameProp);
								for(Aspect aspect: aspectsNameByProperty.get(nameProp)){
									propNode.add(new DefaultMutableTreeNode(aspect.getAspectName()));
								}
								add(propNode);
							}  
						}
					}
					));

		}else{
			tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("None"){{}}));
		}
	}
	
	private List<Aspect> getAspectsSelectedList(){
		List<Aspect> aspectsSelected = new ArrayList<Aspect>();
		
		for(int rowCount =0; rowCount < table.getModel().getRowCount(); rowCount++){
			if(table.getModel().getValueAt(rowCount,2).toString().equals("true")){
				String propName = table.getModel().getValueAt(rowCount,0).toString();
				String aspectName = table.getModel().getValueAt(rowCount,1).toString();

				aspectsSelected.add(new Aspect(aspectName, propName));
			}
		}
		
		return aspectsSelected;
	}

	/* Facade calling methods */
	private void generateCode(){
		try {
			// Se tiver prop selecionadas, se tiver os diretorios ok e se tiver com o nome, do!!
			
			facade.joinCode(new ModelGenerated(getAspectsSelectedList(), txtModelName.getText(), txtImport.getText(), txtExport.getText())); 

			//btnGenerate.setEnabled(false);

			JOptionPane.showMessageDialog(null, "The properties were joined. \n\nModel Name: " + txtModelName.getText()+"\nPath: " + txtExport.getText(), "Successful Operation", JOptionPane.INFORMATION_MESSAGE);

			// TODO Excecao:
			//JOptionPane.showMessageDialog(null, e.getMessage(), e.getExceptionTitle() ,JOptionPane.ERROR_MESSAGE);

			// clear
			//TODO ir pra tela inicial
		} catch (Exception e){
			System.out.println("EROO");
			//JOptionPane.showMessageDialog(null, e.getStackTrace(), AspectLibraryException.INTERNAL_DB_ERROR, JOptionPane.ERROR_MESSAGE);
		}
	}

	private void showYesNoDialog(JTextField txtExport){
		int userResponse = JOptionPane.showConfirmDialog(null ,"Save alterations?","Closing perspective...",JOptionPane.YES_NO_OPTION); 
		if (userResponse == JOptionPane.YES_OPTION) { 
			generateCode();
		}
	}

	private void initialize() {
		/* Frame settings */
		frmSelectionProperty = new JFrame();
		frmSelectionProperty.getContentPane().setBackground(new Color(245, 245, 245));
		frmSelectionProperty.setBounds(100, 100, 793, 682);
		frmSelectionProperty.setResizable(false);
		frmSelectionProperty.setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\F. OMENA\\Dropbox\\Mestrado\\Projeto-Mestrado\\AspectLibrary\\Images\\logo\\logo3.png"));
		frmSelectionProperty.setTitle("Aspect Library v. 1.0 - " + perspective);
		frmSelectionProperty.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmSelectionProperty.setLocation(
				((Toolkit.getDefaultToolkit().getScreenSize().width / 2) - (frmSelectionProperty
						.getWidth() / 2)), ((Toolkit.getDefaultToolkit()
								.getScreenSize().height / 2) - (frmSelectionProperty.getHeight() / 2)));

		JSeparator separator = new JSeparator();
		separator.setForeground(Color.GRAY);

		/* Back button. */
		JButton btnBack = new JButton("< back");
		btnBack.setBackground(SystemColor.controlHighlight);
		btnGenerate.setIcon(new ImageIcon("C:\\Users\\F. OMENA\\Dropbox\\Mestrado\\Projeto-Mestrado\\AspectLibrary\\Images\\buttons\\generate_gray.png"));
		btnGenerate.setBackground(SystemColor.controlHighlight);

		/* Label aspect name. */
		JLabel lblTitle = new JLabel("Set up your properties:");
		lblTitle.setFont(new Font("Arial", Font.PLAIN, 12));

		/* Label step name. */
		JLabel lblStep = new JLabel("Step 1 of 1");
		lblStep.setFont(new Font("Times New Roman", Font.PLAIN, 12));

		try {
			propertiesNames = facade.getPropertiesNames();
		} catch (SQLException e){
			JOptionPane.showMessageDialog(null, e.getStackTrace(), AspectLibraryException.INTERNAL_DB_ERROR, JOptionPane.ERROR_MESSAGE);
		}

		/* Menu bar */
		JMenuBar menuBar = new JMenuBar();
		frmSelectionProperty.setJMenuBar(menuBar);

		/* Menu - File: */
		JMenu mnFile = new JMenu("File");
		mnFile.setMnemonic('f');
		mnFile.setBackground(UIManager.getColor("CheckBox.highlight"));
		menuBar.add(mnFile);

		/* Refresh menu item and separator. */
		JSeparator separator_2 = new JSeparator();
		mnFile.add(separator_2);

		/* Exit menu item. */
		JMenuItem mntmExit = new JMenuItem("Quit");
		mntmExit.setIcon(new ImageIcon("C:\\Users\\F. OMENA\\Dropbox\\Mestrado\\Projeto-Mestrado\\AspectLibrary\\Images\\buttons\\exit_white.png"));
		mntmExit.setBackground(SystemColor.control);
		mntmExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_MASK));
		mnFile.add(mntmExit);

		/* Menu - Help: */
		JMenu mnHelp = new JMenu("Help");
		mnHelp.setMnemonic('h');
		menuBar.add(mnHelp);

		/* Help to use menu item. */
		mntmUsingControls.setBackground(SystemColor.menu);
		mnHelp.add(mntmUsingControls);


		/* Help to use menu item. */
		JLabel lblNewLabel = new JLabel("Selection option");
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 10));
		
		final JCheckBox ckAll = new JCheckBox("all");
		ckAll.setFont(new Font("Tahoma", Font.PLAIN, 10));
		ckAll.setBackground(new Color(245,245,245,245));
		
		final JCheckBox ckNone = new JCheckBox("none");
		ckNone.setFont(new Font("Tahoma", Font.PLAIN, 10));
		ckNone.setBackground(new Color(245,245,245,245));

		/* About menu item. */
		JMenuItem mntmAbout_1 = new JMenuItem("About");
		mntmAbout_1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
		mnHelp.add(mntmAbout_1);
		mntmAbout_1.setBackground(SystemColor.control);
		mntmAbout_1.setIcon(new ImageIcon("C:\\Users\\F. OMENA\\Dropbox\\Mestrado\\Projeto-Mestrado\\AspectLibrary\\Images\\buttons\\about_gray.png"));

		/* Table components */
		// Table column names
		Object[] columnNames = {"Property Name", "Aspect Name","Select It"};

		// Table default rows
		Object[][] data = {   
				{"", "", false}, 	
				{"", "", false},
				{"", "", false},
				{"", "", false},
				{"", "", false},
				{"", "", false},
				{"", "", false},
				{"", "", false},
				{"", "", false}
		};

		// Model with names and rows.
		final DefaultTableModel model = new DefaultTableModel(data, columnNames);

		// Edit table inherited methods. 
		table = new JTable(model) {
			// Class of column
			@Override
			public Class getColumnClass(int column) {
				switch (column) {
				case 0:
					return String.class;
				case 1:
					return String.class;
				default:
					return Boolean.class;
				}
			}

			// Editable rows
			@Override
			public boolean isCellEditable(int row, int column) {
				// Is editable if is the last column (boolean choice) and the first line has content. 
				if(column>1 && !table.getModel().getValueAt(row, 0).toString().equals("")){
					return true;
				}
				return false;
			}
		};

		// Set table dimension
		table.setPreferredSize(new Dimension(600, 200));  

		// Sets columns dimension
		table.getColumnModel().getColumn(0).setPreferredWidth(297);  
		table.getColumnModel().getColumn(1).setPreferredWidth(297);
		table.getColumnModel().getColumn(2).setPreferredWidth(6);

		// Create a sroll
		JScrollPane scroll = new JScrollPane(table);

		/* Table components */
		// Label component.
		JLabel lblHierarq = new JLabel("Properties selected");
		lblHierarq.setFont(new Font("Arial", Font.PLAIN, 12));

		// Scroll component.
		treeScroll = new JScrollPane();

		/* Check box is a new model component. */
		final JCheckBox ckIsNewModel = new JCheckBox("is a new");
		ckIsNewModel.setBackground(new Color(245,245,245,245));
		ckIsNewModel.setFont(new Font("Tahoma", Font.PLAIN, 10));

		/* Export model components. */
		txtExport.setEditable(false);
		txtExport.setText("C:\\");
		txtExport.setToolTipText("");
		txtExport.setColumns(10);

		JButton btnExportModel = new JButton("Export");
		btnExportModel.setToolTipText("");
		btnExportModel.setIcon(new ImageIcon("C:\\Users\\F. OMENA\\Dropbox\\Mestrado\\Projeto-Mestrado\\AspectLibrary\\Images\\buttons\\export_gray.png"));
		btnExportModel.setBackground(SystemColor.controlHighlight);

		/* Import model components. */
		txtImport.setEditable(false);
		txtImport.setText("C:\\");
		txtImport.setToolTipText("");
		txtImport.setColumns(10);

		final JButton btnImportModel = new JButton("Import");
		btnImportModel.setToolTipText("");
		btnImportModel.setIcon(new ImageIcon("C:\\Users\\F. OMENA\\Dropbox\\Mestrado\\Projeto-Mestrado\\AspectLibrary\\Images\\buttons\\import_gray.png"));
		btnImportModel.setBackground(SystemColor.controlHighlight);

		/* -------------------- Events -------------------- */

		/* About button event. */
		mntmAbout_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				aboutUs.setVisible(true);	
			}
		});

		/* Exit buttons event. */
		mntmExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//				if(btnSave.isEnabled() || mntmSave.isEnabled()){
				//					showYesNoDialog();
				//				}
				System.exit(0);
			}
		});

		/* Back button event. */
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				/* Its not enable when the aspect was saved. */
				//				if(btnSave.isEnabled() || mntmSave.isEnabled()){
				//					showYesNoDialog();
				//				}
				back();
			}
		});

		/* Save buttons event. */
		btnGenerate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				generateCode();
			}
		});

		/* Check boxes for select properties event. */
		ckAll.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(ckAll.isSelected()){
					selectAllOrNoneRows(true);

					ckNone.setSelected(false);
				}
				populateTree();
			}
		});

		ckNone.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(ckNone.isSelected()){
					selectAllOrNoneRows(false);

					ckAll.setSelected(false);
				}
				populateTree();
			}
		});
		
		ckIsNewModel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(ckIsNewModel.isSelected()){
					btnImportModel.setEnabled(false);
					txtImport.setText("");
				}else{
					btnImportModel.setEnabled(true);
					txtImport.setText("C:\\");
				}
			}
		});
		
		/* Import and export button event. */
		btnImportModel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				boolean importTxtIsValid = (txtImport!=null && txtImport.getText()!=null && !txtImport.getText().equals("") && !txtImport.getText().equals(" "));
				JFileChooser fc = new JFileChooser(new File(importTxtIsValid ? txtImport.getText() : "C:\\"));
				fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
				fc.setDialogTitle("Importing model..");
				int res = fc.showOpenDialog(null);

				if (res == JFileChooser.APPROVE_OPTION) {
					File path = fc.getSelectedFile();
					txtImport.setText(path.getAbsolutePath());
					//verificar se tem .nlogo TODO!!
				}
			}
		});
		
		btnExportModel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				boolean exportTxtIsValid = (txtExport!=null && txtExport.getText()!=null && !txtExport.getText().equals("") && !txtExport.getText().equals(" "));
			
				JFileChooser fc = new JFileChooser(new File(exportTxtIsValid ? txtExport.getText() : "C:\\"));
				fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				fc.setDialogTitle("Setting path to export..");
				int res = fc.showOpenDialog(null);

				if (res == JFileChooser.APPROVE_OPTION) {
					File path = fc.getSelectedFile();
					txtExport.setText(path.getAbsolutePath()); //falta nome arquivo e ver se entrou if
				}
			}
		});

		/* Table event. */
		table.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				populateTree();
			}
		});


		/* Layout: */
		
		JLabel lblExportPath = new JLabel("Where export");
		lblExportPath.setFont(new Font("Arial", Font.PLAIN, 12));
		
		JLabel lblImportPath = new JLabel("Where import");
		lblImportPath.setFont(new Font("Arial", Font.PLAIN, 12));
		
		JLabel lblModelName = new JLabel("Model Name");
		lblModelName.setFont(new Font("Arial", Font.PLAIN, 12));
		
		txtModelName.setColumns(10);
		
		GroupLayout groupLayout = new GroupLayout(frmSelectionProperty.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(treeScroll, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 440, GroupLayout.PREFERRED_SIZE)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblExportPath)
							.addContainerGap(705, Short.MAX_VALUE))
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblModelName, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
							.addContainerGap(699, Short.MAX_VALUE))
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(txtModelName, GroupLayout.PREFERRED_SIZE, 172, GroupLayout.PREFERRED_SIZE)
							.addContainerGap(605, Short.MAX_VALUE))
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(separator, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblTitle))
							.addPreferredGap(ComponentPlacement.RELATED, 698, Short.MAX_VALUE)
							.addComponent(lblStep)
							.addContainerGap())
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(btnBack)
							.addPreferredGap(ComponentPlacement.RELATED, 714, Short.MAX_VALUE)
							.addComponent(btnGenerate)
							.addContainerGap())
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(txtExport, GroupLayout.PREFERRED_SIZE, 340, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(btnExportModel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblImportPath, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(ckIsNewModel)
									.addGap(288))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(txtImport, GroupLayout.PREFERRED_SIZE, 340, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(btnImportModel)))
							.addGap(339))
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
								.addGroup(groupLayout.createSequentialGroup()
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addGroup(groupLayout.createSequentialGroup()
											.addComponent(lblHierarq, GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
											.addGap(410))
										.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
											.addComponent(lblNewLabel)
											.addPreferredGap(ComponentPlacement.RELATED)))
									.addComponent(ckAll)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(ckNone))
								.addComponent(scroll, GroupLayout.DEFAULT_SIZE, 874, Short.MAX_VALUE))
							.addContainerGap())))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(separator, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
							.addComponent(lblTitle)
							.addComponent(lblStep)))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(scroll, GroupLayout.PREFERRED_SIZE, 186, GroupLayout.PREFERRED_SIZE)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(26)
							.addComponent(lblHierarq, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(treeScroll, GroupLayout.PREFERRED_SIZE, 125, GroupLayout.PREFERRED_SIZE)
							.addGap(20)
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblImportPath)
								.addComponent(ckIsNewModel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(btnImportModel)
								.addComponent(txtImport, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE))
							.addGap(12)
							.addComponent(lblExportPath)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(txtExport, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
								.addComponent(btnExportModel))
							.addGap(13)
							.addComponent(lblModelName, GroupLayout.PREFERRED_SIZE, 13, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(txtModelName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(groupLayout.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(ckNone)
								.addComponent(ckAll)
								.addComponent(lblNewLabel))))
					.addGap(27)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnBack)
						.addComponent(btnGenerate))
					.addContainerGap(21, Short.MAX_VALUE))
		);
		
				// Creating tree component.
				tree = new JTree();
				treeScroll.setViewportView(tree);
				
						// Elements setting - None nodes.
						tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("None"){{}}));

		frmSelectionProperty.getContentPane().setLayout(groupLayout);
	}
}
